<template>
  <div>
    <el-form :model="formItem" label-width="100px" size="mini" class="form-view">
      <el-row :gutter="40">
        <el-col :span="8">
          <el-form-item label="规则名称">
            {{ formItem.name }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="维护类别">
            {{ formItem.modelName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="维护对象">
            {{ formItem.objName }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="40">
        <el-col :span="8">
          <el-form-item label="是否停止服务">
            {{ formItem.suspendService === true ? '是' : '否' }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="量化时间">
            {{ formItem.quantifyingTime }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="40">
        <el-col :span="24">
          <el-form-item label="维护说明">
            <div class="richWraper" v-html="formItem.description" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import {
  detail as taskDetail
} from '@neu/dcom-ui/api/maintainTask'
import {
  detail
} from '@neu/dcom-ui/api/maintainRule'

const formItem = {
  name: '',
  modelCode: null,
  modelName: '',
  suspendService: '',
  quantifyingTime: null,
  description: '',
  objName: '',
  rule: ''
}
export default {
  name: 'TmpMaintainTaskViewRuleForm',
  props: {
    id: {
      required: false,
      type: Number,
      default: -1
    },
    taskId: {
      required: false,
      type: Number,
      default: -1
    }
  },
  data() {
    return {
      formItem: {
        ...formItem
      }
    }
  },
  watch: {
    id: function() {
      this.fetch()
    }
  },
  created() {
    this.fetch()
  },
  methods: {
    fetch() {
      if (this.id !== -1) {
        if (this.taskId !== -1) {
          taskDetail(this.taskId).then(response => {
            this.formItem = {
              ...response.data
            }
            this.formItem.description = this.formItem.rule.description
          })
        } else {
          detail(this.id).then(response => {
            this.formItem = {
              ...response.data
            }
          })
        }
      } else {
        this.formItem = {
          ...formItem
        }
      }
    }
  }
}
</script>
